home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / asendhsf.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  12KB  |  295 lines

  1.  /**********************************************************
  2.  *                                                         *
  3.  *                      SENDHS                             *
  4.  *                SEND record to HS                        *
  5.  * This procedure make request to the HS for send processing
  6.  * with appropriate parms.                                 *
  7.  * This parms are :                                        *
  8.  *                  - FMH;                                 *
  9.  *                  - Send_data;                           *
  10.  *                  - Confirm;                             *
  11.  *                  - Confirmed;                           *
  12.  *                  - Flash;                               *
  13.  *                  - PREP_TO_RCV_FLUSH;                   *
  14.  *                  - PREP_TO_RCV_CONFIRM_SH;              *
  15.  *                  - PREP_TO_RCV_CONFIRM_LG;              *
  16.  *                  - Req_to_send;                         *
  17.  *                  - Deallocate_confirm;                  *
  18.  *                  - Deallocate_flush;                    *
  19.  *                  - Deallocate_abend;                    *
  20.  *                                                         *
  21.  * INPUT : pointer to RCB.                                 *
  22.  *                                                         *
  23.  * OUTPUT: - 0 - OK;                                       *
  24.  *         - 1 - an invalid request;                       *
  25.  *         - 2 - a return code is in RPL.                  *
  26.  *                                                         *
  27.  *                                                         *
  28.  * CopyRight 1995. Nicholas Poljakov all rights reserved.  *
  29.  *                                                         *
  30.  **********************************************************/
  31. #include <stdio.h>
  32. #include <malloc.h>
  33. #include <rcb.h>
  34. #include <dall.h>
  35. #include <scb.h>
  36. #include <prefix.h>
  37. #include <include.h>
  38. #include <string.h>
  39. #include <state1.h>
  40.  
  41. #define PRF_SIZ 31
  42.  
  43. int sk_r_wt(void *);
  44. int SendBlock(void *, void *);
  45. int setrc(void *, void *);
  46. int sendhs(void *);
  47. int sendbm(void *, void *);
  48. int sendat(void *);
  49. int rtsend(void *);
  50. unsigned long rmfmh5(void *, void *);
  51. int recwait(void *);
  52. int rcvru(void *, void *);
  53. int rcvhs(void *, void *, void *, void *);
  54. int ralloc(void *, void *);
  55. int psrm(int, void *, void *);
  56. int ps_conv(int, void *);
  57. int proterr(void *, unsigned long);
  58. int preptrcv(void *, void *);
  59. int post_rcb(void *);
  60. struct repass *postopen(void *);
  61. int phsrec(void *);
  62. int pfmh5(void *);
  63. int opndst(void *);
  64. int obtsess(void *, unsigned char);
  65. int Lrf_handler(void *);
  66. int get_sess(void *, void *);
  67. int get_attr(void *);
  68. int fsm_error(unsigned char, void *);
  69. int fsm_conv(unsigned char, unsigned char, void *);
  70. int flush (void *);
  71. int dcp(void *);
  72. int dealloc(void *);
  73. int crtp(void *);
  74. int conv(void *);
  75. int chkparm(void *, void *);
  76. int check_end(unsigned int, void *);
  77. struct rqb *call_appl(void *);
  78. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  79. unsigned long attltck(void *);
  80. unsigned long attacheck(void *);
  81. char *cgetmem(int, int);
  82. int sendhsf(void *);
  83. int opndst(void *);
  84. int alloc_rcb(void *, void *);
  85. int allocate(void *);
  86. int clsdst(void *);
  87. int short sem_no;
  88.  
  89. sendhsf(p_rcb)
  90. struct rcb *p_rcb;
  91. {
  92.         struct scb *p_scb;
  93.         struct prefix *p_prf;
  94.         struct prefix *t_prf;
  95.         struct prefix *tt_prf;
  96.         struct segprf *p_sp;
  97.         struct segprf *t_sp;
  98.         struct rqb *p_rqb;
  99.         struct deallocate *p_dal;
  100.         char p1;
  101.         char *p;
  102.         char *p_rh;
  103.         char *p_ru;
  104.         unsigned int cnt;
  105.         unsigned int cnt1;
  106.         char *buff;
  107.         int rc;
  108.         unsigned char type;
  109.         int i;
  110.         unsigned char dsc;
  111.  
  112.         rc = 0;
  113.         cnt1 = 0;
  114.  
  115.         if (p_rcb -> p_scb == NULL) {
  116.              rc = 2;
  117.              goto sd_exit;
  118.         }
  119.         p_scb = p_rcb -> p_scb;
  120.  
  121.         do {
  122.              p_prf = p_rcb -> first_out;
  123.              if (p_prf == NULL) {
  124.                     rc = 1;
  125.                      goto sd_exit;
  126.                   }
  127.              cnt = 0;
  128.                         do {    /* for send state */
  129.                              type = p_prf ->type;
  130.                              switch (type)
  131.                                     {
  132.                                         case Fmh :
  133.                                         {
  134.                                             cnt += p_prf -> lt_text;
  135.                                             break;
  136.                                          }
  137.                                          case Send_data :
  138.                                          {
  139.                                             if (( cnt + p_prf -> lt_text) > MAX_RU )
  140.                                                     goto DOEX;
  141.                                             cnt += p_prf -> lt_text;
  142.                                             break;
  143.                                          }
  144.                                          default :
  145.                                             goto DOEX;
  146.                                     } /* end of switch */
  147.                              p_prf = p_prf -> next;
  148.                } while (p_prf != NULL );
  149.              DOEX:
  150.  
  151.                           if ((p_sp = calloc(1,(cnt + PRF_SIZ))) == NULL) {
  152.                               rc = 1;
  153.                               goto sd_exit;
  154.                           }
  155.                  p = p_sp;
  156.                  p_sp -> len = cnt + 3;
  157.                  p_rqb = p + 12;
  158.                  p_ru = p + PRF_SIZ;
  159.                  p_rh = p + 28 ;
  160.                  p_prf = p_rcb -> first_out;
  161.                  cnt1 = 0;
  162.                  dsc = 0;
  163.                  p_rqb -> th.ra.wa.hh.hscb = p_rcb -> sess_corl;
  164.                  p_rqb -> th.ra.wa.rqba.rclass = cnt;
  165.                  p_rqb -> th.ra.stcb = APPL_CODE;
  166.                  p_rqb -> th.ra.code = p_rqb -> th.ra.code & 0xbf; /* TOP */
  167.                  p_rqb -> th.ra.wa.rqba.rsrlen = sem_no;
  168.                  p_rqb -> th.ra.rparm.parm.parm1 = 1; /* Send */
  169.  
  170.                  do {
  171.                        type = p_prf -> type;
  172.                        switch (type)
  173.                             {
  174.                               case Confirm :
  175.                                      { *p_rh |=0x01;
  176.                                        *(p_rh + 1) |=0xa0;
  177.                                        dsc = 1;
  178.                                        break;
  179.                                      }
  180.                               case COnfirmed :
  181.                                      {
  182.                                         *p_rh |= 0x81;
  183.                                         *(p_rh + 1) |= 0xa0;
  184.                                         dsc = 1;
  185.                                          break;
  186.                                       }
  187.                               case Request_to_send :
  188.                                       {
  189.                                         *p_rh |= 0x0b;
  190.                                         *(p_rh + 1) |= 0x80;
  191.                                         dsc = 1;
  192.                                         break;
  193.                                       }
  194.                               case Fmh :
  195.                                        {
  196.                                          *p_rh |= 0x0a;
  197.                                          memcpy( p_ru,p_prf->text,p_prf->lt_text);
  198.                                          p_ru += p_prf ->lt_text;
  199.                                          cnt1 += p_prf -> lt_text;
  200.                                          break;
  201.                                        }
  202.                               case Send_data :
  203.                                        {
  204.                                          if (( cnt1 + p_prf ->lt_text ) > cnt )
  205.                                                 goto FULLSG;
  206.                                          *(p_rh + 1) |=0x90;
  207.                                          memcpy( p_ru,p_prf->text,p_prf->lt_text);
  208.                                          p_ru += p_prf ->lt_text;
  209.                                          cnt1 += p_prf -> lt_text;
  210.                                          break;
  211.                                        }
  212.                               case Flush :
  213.                                        {
  214.                                         *(p_rh + 1) |= 0x90;
  215.                                         dsc = 1;
  216.                                         break;
  217.                                        }
  218.                               case PREP_TO_RCV_FLUSH :
  219.                                        {
  220.                                         *p_rh |= 0x01;
  221.                                         *(p_rh + 1) |= 0x90;
  222.                                         *(p_rh + 2) |= 0x20;
  223.                                         dsc = 1;
  224.                                         break;
  225.                                        }
  226.                               case PREP_TO_RCV_CONFIRM_SH :
  227.                                        {
  228.                                         *p_rh |= 0x01;
  229.                                         *(p_rh + 1) |= 0xa0;
  230.                                         *(p_rh + 2) |= 0x20;
  231.                                         dsc = 1;
  232.                                         break;
  233.                                        }
  234.                               case PREP_TO_RCV_CONFIRM_LG :
  235.                                        {
  236.                                         *p_rh |= 0x01;
  237.                                         *(p_rh + 1) |= 0xb0;
  238.                                         *(p_rh + 2) |= 0x20;
  239.                                         dsc = 1;
  240.                                         break;
  241.                                        }
  242.                               case Deallocate_confirm :
  243.                                        {
  244.                                         *p_rh |= 0x01;
  245.                                         *(p_rh + 1) |= 0xa0;
  246.                                         *(p_rh + 2) |= 0x01;
  247.                                         dsc = 1;
  248.                                         break;
  249.                                        }
  250.                               case Deallocate_flush :
  251.                                        {
  252.                                         *p_rh |= 0x01;
  253.                                         *(p_rh + 1) |= 0xb0;
  254.                                         *(p_rh + 2) |= 0x01;
  255.                                         dsc = 1;
  256.                                         break;
  257.                                        }
  258.                             }     /* end of switch */
  259.  
  260.                          t_prf = p_prf;
  261.                          p_prf = p_prf -> next;
  262.                          buffmng( 'D',t_prf,&((*p_rcb).first_out),p_rcb,0,0,0);
  263.             } while ((p_prf != NULL) && (cnt1 <= cnt) && (dsc == 0 ));
  264.  
  265.    FULLSG:
  266.         call_appl(p_rqb);
  267.         free(p_sp);
  268.  
  269.        } while ( (p_rcb -> first_out) != NULL );
  270.  
  271.  
  272. sd_exit:
  273.          switch (rc) {
  274.             case 0 :
  275.                       {
  276.                           p1 = RESET;
  277.                           fsm_error(p1, p_rcb);
  278.                           break;
  279.                       }
  280.             case 1 :
  281.                       {
  282.                           p1 = ALLOC_FAIL_RETRY;
  283.                           fsm_error(p1, p_rcb);
  284.                           break;
  285.                       }
  286.             case 2 :
  287.                       {
  288.                           p1 = ALLOC_FAIL_NO_RETRY;
  289.                           fsm_error(p1, p_rcb);
  290.                           break;
  291.                       }
  292.           }
  293.          return (rc);
  294. }
  295.